package easy

import "unicode"

func ReverseOnlyLetters(s string) string {
	ans := []byte(s)
	first := 0
	last := len(s) - 1
	for first < last {
		for first < last && !unicode.IsLetter(rune(s[first])) {
			first++
		}
		for first < last && !unicode.IsLetter(rune(s[last])) {
			last--
		}
		ans[first], ans[last] = ans[last], ans[first]
		first++
		last--
	}
	return string(ans)
}
